package com.gupao.rpc.protocol.serializer;

import com.alibaba.fastjson.JSON;
import com.gupao.rpc.protocol.constants.SerialType;

/**
 * json序列化
 *
 * @author SuperWein
 */
public class JsonRpcSerializer implements IRpcSerializer {

    @Override
    public <T> byte[] serialize(T obj) {
        return JSON.toJSONString(obj).getBytes();
    }

    @Override
    public <T> T deserialize(byte[] bytes, Class<T> clazz) {
        return JSON.parseObject(bytes, clazz);
    }

    @Override
    public byte getType() {
        return SerialType.JSON.value();
    }

}
